home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Night Owl 6
/
Night Owl's Shareware - PDSI-006 - Night Owl Corp (1990).iso
/
027a
/
vntx.zip
/
CORRUPT.PRG
< prev
next >
Wrap
Text File
|
1991-02-07
|
3KB
|
99 lines
#include "fileio.ch"
#include "corrupt.ch"
static nNtx, nKeySize, bKey, nStatus, nCol, nChecked, nProblemRecno
/*--------------------------------CORRUPTED-----------------------------------*/
function corrupted(sDbfName, ; // name of database on which index is based
sNtxName, ; // name of index to check for corruption
nRecno) // record number of offending record, if any
local sBuffer, nRootPtr, sKeyExpr := '', sOldScrn, nOldArea := select()
local nOldCoords := {row(), col()}, nOldCursor := setCursor(0)
* begin
if ( (sDbfName == NIL) .or. (sNtxName == NIL) ); return CO_NTXOPEN; end
if ( !('.' $ sDbfName) ); sDbfName += '.dbf'; end
if ( !('.' $ sNtxName) ); sNtxName += '.ntx'; end
if ( !file(sDbfName) ); return CO_BADDBF; end
nNtx := fopen(sNtxName, FO_READ)
if ( nNtx < 0 ); return CO_NTXOPEN; end
fSeek(nNtx, 4, FS_SET) //read offset to root node
sBuffer := space(4)
if ( fRead(nNtx, @sBuffer, 4) < 4 )
fclose(nNtx)
return CO_NTXREAD
end
nRootPtr := bin2L(sBuffer)
fSeek(nNtx, 14, FS_SET) //read key size
sBuffer := space(4)
fRead(nNtx, @sBuffer, 4)
nKeySize := bin2L(sBuffer)
fSeek(nNtx, 22, FS_SET) //read key expression and compile
sBuffer := space(1)
fRead(nNtx, @sBuffer, 1)
while ( asc(sBuffer) <> 0 )
sKeyExpr += sBuffer
sBuffer := space(1)
fRead(nNtx, @sBuffer, 1)
end
bKey := &('{ || ' + alltrim(sKeyExpr) + ' }')
use (sDbfName) new
sOldScrn := savescreen(10, 2, 12, 78)
@ 10,2 clear to 12,78
@ 10,2 to 12,78
@ 11,3 say ' Verifying ' + sNtxName + ' of ' + sDbfName + '. 0/' + ;
str(lastrec(), 10, 0) + ' verified. '
nCol := len(sDbfName) + len(sNtxName) + 21
nChecked := 0
nProblemRecno := 0
nStatus := CO_OK
traverse(nRootPtr)
nRecno := nProblemRecno
select (nOldArea)
restscreen(10, 2, 12, 78, sOldScrn)
setCursor(nOldCursor)
@ nOldCoords[1], nOldCoords[2] say ''
return nStatus
/*---------------------------------TRAVERSE-----------------------------------*/
function traverse(nNodePtr)
local sPage := space(1024), nEntryCount, nI := 1, nEntryPtr
local aEntry := { 0, 0, '' }
* begin
if ( nNodePtr == 0 ); return NIL; end
fSeek(nNtx, nNodePtr, FS_SET)
fRead(nNtx, @sPage, 1024)
nEntryCount := bin2I(sPage)
while ( (nStatus == CO_OK) .and. (nI <= nEntryCount) )
nChecked++
@ 11, nCol say str(nChecked, 10, 0)
getEntry(@sPage, nI, nKeySize, aEntry)
if ( aEntry[CO_RECNO] > lastrec() )
nStatus := CO_BADRECNO
nProblemRecno := aEntry[CO_RECNO]
else
goto aEntry[CO_RECNO]
if ( aEntry[CO_KEY] <> eval(bKey) )
nStatus := CO_BADKEY
nProblemRecno := aEntry[CO_RECNO]
else
traverse(aEntry[CO_CHILD])
nI++
end
end
end
if ( nStatus == CO_OK )
getEntry(@sPage, nI, nKeySize, aEntry)
traverse(aEntry[CO_CHILD])
end
return NIL